package com.medium.house.service.impl;

import com.medium.house.entity.HousePointRef;
import com.medium.house.repository.HousePointRefMapper;
import com.medium.house.service.HousePointRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : wang.yu
 * @Description :
 * @Date: Created in 2018/2/27 0027  16:10
 * @Modified By
 */
@Service
public class HousePointRefServiceImpl  implements HousePointRefService {

    @Autowired
    private HousePointRefMapper housePointRefMapper;
    @Override
    public int add(HousePointRef dto)
    {
        return housePointRefMapper.insert(dto);
    }

    @Override
    public int delete(long id)
    {
        return housePointRefMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(HousePointRef dto)
    {
        return housePointRefMapper.updateByPrimaryKeySelective(dto);
    }

    @Override
    public HousePointRef get(long id)
    {
        return housePointRefMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HousePointRef> getByPage(
            int start,
            int limit,
            int orderby,
            int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HousePointRefMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return housePointRefMapper.selectByPage(start, limit, HousePointRefMapper.ORDERBY[orderby], HousePointRefMapper.ORDER[order], args);
    }

    @Override
    public List<Long> getIdsByPage(
            int start,
            int limit,
            int orderby,
            int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HousePointRefMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return housePointRefMapper.selectIdsByPage(start, limit, HousePointRefMapper.ORDERBY[orderby], HousePointRefMapper.ORDER[order], args);
    }

    @Override
    public long count()
    {
        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return housePointRefMapper.count(args);
    }
}
